/**
 * @Copyright:Copyright (c) 2007 - 2023
 * 
 */
package com.tengtong.commons.lang;

import java.time.LocalDate;
import java.time.format.DateTimeFormatterBuilder;

/**
 * 日期工具
 *
 * @author lin_jinming
 * @since: v1.0
 */
public class DatetimeUtils {

    /**
     * 判断日期时间字符串是否合法
     *
     * @param date
     * @param pattern
     * @return
     */
    public final static boolean isDate(String date, String pattern) {
        if(StringUtils.isNullOrEmpty(pattern)) {
            pattern = "yyyy-MM-dd HH:mm:ss";
        }
        try {
            LocalDate.parse(
                    date, 
                    new DateTimeFormatterBuilder()
                        .appendPattern(pattern)
                        .parseStrict()
                        .toFormatter());
            return true;
        }
        catch (Exception e) {
            return false;
        }
    }
}
